


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > Bill</title>
  <style type="text/css">
    @import "../../.css/coverage.css";
    @import "../../.css/highlight-idea.css";
  </style>
  <script type="text/javascript" src="../../.js/highlight.pack.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">gradle1</a>
</div>

<h1>Coverage Summary for Class: Bill (gradle1)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">Bill</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (3/3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    94.3%
  </span>
  <span class="absValue">
    (33/35)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<div class="sourceCode" id="sourceCode"><i class="no-highlight">1</i>&nbsp;package gradle1;
<i class="no-highlight">2</i>&nbsp;
<i class="no-highlight">3</i>&nbsp;import java.text.ParseException;
<i class="no-highlight">4</i>&nbsp;import java.text.SimpleDateFormat;
<i class="no-highlight">5</i>&nbsp;import java.util.Calendar;
<i class="no-highlight">6</i>&nbsp;import java.util.Date;
<i class="no-highlight">7</i>&nbsp;
<b class="fc"><i class="no-highlight">8</i>&nbsp;public class Bill {</b>
<i class="no-highlight">9</i>&nbsp;    public long calculateTime(String startTime, String endTime) throws ParseException {
<b class="fc"><i class="no-highlight">10</i>&nbsp;        SimpleDateFormat format1 = new SimpleDateFormat(&quot;yyyyMMddHHmmss&quot;);</b>
<b class="fc"><i class="no-highlight">11</i>&nbsp;        Date date1 = format1.parse(startTime);</b>
<b class="fc"><i class="no-highlight">12</i>&nbsp;        Date date2 = format1.parse(endTime);</b>
<b class="fc"><i class="no-highlight">13</i>&nbsp;        Calendar cal1 = Calendar.getInstance();</b>
<b class="fc"><i class="no-highlight">14</i>&nbsp;        cal1.setTime(date1);</b>
<b class="fc"><i class="no-highlight">15</i>&nbsp;        Calendar cal2 = Calendar.getInstance();</b>
<b class="fc"><i class="no-highlight">16</i>&nbsp;        cal2.setTime(date2);</b>
<b class="fc"><i class="no-highlight">17</i>&nbsp;        long phonetime = cal2.getTime().getTime() - cal1.getTime().getTime();</b>
<i class="no-highlight">18</i>&nbsp;        long minute;
<i class="no-highlight">19</i>&nbsp;
<b class="fc"><i class="no-highlight">20</i>&nbsp;        if (phonetime &gt;= 0 &amp;&amp; phonetime / 1000 &lt; 60 || phonetime % 60000 &gt; 0) //不到一分钟按一分钟计算</b>
<b class="fc"><i class="no-highlight">21</i>&nbsp;            minute = phonetime / 1000 / 60 + 1;</b>
<i class="no-highlight">22</i>&nbsp;        else
<b class="fc"><i class="no-highlight">23</i>&nbsp;            minute = phonetime / 1000 / 60;</b>
<i class="no-highlight">24</i>&nbsp;
<b class="fc"><i class="no-highlight">25</i>&nbsp;        if (cal1.get(Calendar.MONTH) == Calendar.OCTOBER &amp;&amp; cal1.get(Calendar.DATE) &gt;= 25 &amp;&amp; cal1.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {</b>
<i class="no-highlight">26</i>&nbsp;            //开始时间在十月最后一个周日
<b class="fc"><i class="no-highlight">27</i>&nbsp;            if (cal1.get(Calendar.HOUR_OF_DAY) == 2 &amp;&amp; cal2.get(Calendar.HOUR_OF_DAY) == 2 &amp;&amp; cal2.get(Calendar.HOUR_OF_DAY) &lt; 3 &amp;&amp; cal2.get(Calendar.MINUTE) &lt;= cal1.get(Calendar.MINUTE)) {</b>
<i class="no-highlight">28</i>&nbsp;                //因为转换而出现通话时间为负的情况
<b class="fc"><i class="no-highlight">29</i>&nbsp;                minute += 60;</b>
<i class="no-highlight">30</i>&nbsp;//                System.out.println(&quot;通话时长：&quot;+minute);
<i class="no-highlight">31</i>&nbsp;//                System.out.println(&quot;通话账单：&quot;+Money(minute));
<b class="fc"><i class="no-highlight">32</i>&nbsp;            } else if (cal1.get(Calendar.HOUR_OF_DAY) &lt; 2 &amp;&amp; cal2.get(Calendar.HOUR_OF_DAY) &gt;= 2) {</b>
<i class="no-highlight">33</i>&nbsp;                //开始时间是两点前，结束时间是两点后（经历第二次转换
<i class="no-highlight">34</i>&nbsp;//                System.out.println(&quot;通话时长：&quot;+minute+&quot;或&quot;+(minute+60));
<i class="no-highlight">35</i>&nbsp;//                System.out.println(&quot;通话账单：&quot;+Money(minute)+&quot;或&quot;+Money(minute+60));
<i class="no-highlight">36</i>&nbsp;            } else {
<b class="fc"><i class="no-highlight">37</i>&nbsp;                minute = minute;</b>
<i class="no-highlight">38</i>&nbsp;//                System.out.println(&quot;通话时长：&quot;+minute);
<i class="no-highlight">39</i>&nbsp;//                System.out.println(&quot;通话账单：&quot;+Money(minute));
<i class="no-highlight">40</i>&nbsp;            }
<b class="fc"><i class="no-highlight">41</i>&nbsp;            return minute;</b>
<i class="no-highlight">42</i>&nbsp;        } else {
<b class="fc"><i class="no-highlight">43</i>&nbsp;            if (cal2.get(Calendar.MONTH) == Calendar.OCTOBER &amp;&amp; cal2.get(Calendar.DATE) &gt;= 25 &amp;&amp; cal2.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {</b>
<b class="fc"><i class="no-highlight">44</i>&nbsp;                if (cal2.get(Calendar.HOUR_OF_DAY) &gt;= 2)</b>
<b class="fc"><i class="no-highlight">45</i>&nbsp;                    minute += 60;</b>
<i class="no-highlight">46</i>&nbsp;            } else {
<b class="fc"><i class="no-highlight">47</i>&nbsp;                if ((cal1.get(Calendar.MONTH) == Calendar.MARCH &amp;&amp; cal1.get(Calendar.DATE) &gt;= 25 &amp;&amp; cal1.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) {</b>
<i class="no-highlight">48</i>&nbsp;                    //开始时间在三月最后一个周日
<b class="fc"><i class="no-highlight">49</i>&nbsp;                    if (cal1.get(Calendar.HOUR_OF_DAY) &lt; 2 &amp;&amp; cal2.get(Calendar.HOUR_OF_DAY) &gt;= 3)</b>
<i class="no-highlight">50</i>&nbsp;                        //开始时间在两点前，结束时间在三点后（经过了第一次转换
<b class="fc"><i class="no-highlight">51</i>&nbsp;                        minute -= 60;</b>
<i class="no-highlight">52</i>&nbsp;                } else {//开始时间不在三月最后一个周日
<b class="fc"><i class="no-highlight">53</i>&nbsp;                    if ((cal2.get(Calendar.MONTH) == Calendar.MARCH &amp;&amp; cal2.get(Calendar.DATE) &gt;= 25 &amp;&amp; cal2.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) {</b>
<i class="no-highlight">54</i>&nbsp;                        //但是结束时间在（从前一天打到这一天
<b class="nc"><i class="no-highlight">55</i>&nbsp;                        if (cal2.get(Calendar.HOUR_OF_DAY) &gt;= 3)</b>
<b class="nc"><i class="no-highlight">56</i>&nbsp;                            minute -= 60;</b>
<i class="no-highlight">57</i>&nbsp;                    }
<i class="no-highlight">58</i>&nbsp;                }
<i class="no-highlight">59</i>&nbsp;            }
<i class="no-highlight">60</i>&nbsp;        }
<b class="fc"><i class="no-highlight">61</i>&nbsp;        return minute;</b>
<i class="no-highlight">62</i>&nbsp;    }
<i class="no-highlight">63</i>&nbsp;
<i class="no-highlight">64</i>&nbsp;    public String Money(long minute) {
<b class="fc"><i class="no-highlight">65</i>&nbsp;        double money = 0;</b>
<b class="fc"><i class="no-highlight">66</i>&nbsp;        if (minute &gt; 1200 || minute &lt;= 0) {</b>
<b class="fc"><i class="no-highlight">67</i>&nbsp;            return &quot;通话时间输入错误，请重新输入。&quot;;</b>
<i class="no-highlight">68</i>&nbsp;        } else {
<b class="fc"><i class="no-highlight">69</i>&nbsp;            if (minute &lt;= 20)</b>
<b class="fc"><i class="no-highlight">70</i>&nbsp;                money = minute * 0.05;</b>
<i class="no-highlight">71</i>&nbsp;            else
<b class="fc"><i class="no-highlight">72</i>&nbsp;                money = 1 + (minute - 20) * 0.1;</b>
<b class="fc"><i class="no-highlight">73</i>&nbsp;            return money + &quot;元&quot;;</b>
<i class="no-highlight">74</i>&nbsp;        }
<i class="no-highlight">75</i>&nbsp;    }
<i class="no-highlight">76</i>&nbsp;}
</div>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
        var codeBlock = document.getElementById('sourceCode');

        if (codeBlock) {
            hljs.highlightBlock(codeBlock);
        }
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2022-04-03 16:31</div>
</div>
</body>
</html>
